package com.lndsnx.test;

import java.util.Random;

/**
 * @author lndsnx
 * @Description 把一个一维数组 0~15 打乱顺序，4个一组的方式添加到二维数组
 * @Version 1.0.0
 * @Date 2023/5/11,0011 22:59
 */
public class TwoArrayTest2 {

    public static void main(String[] args) {
        int[] arr = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            int index = r.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();

        int[][] date = new int[4][4];

        int index = 0;
        for (int i = 0; i < date.length; i++) {
            for (int j = 0; j < date.length; j++) {
                date[i][j] = arr[index++];
            }
        }

        for (int i = 0; i < date.length; i++) {
            for (int j = 0; j < date.length; j++) {
                System.out.print(date[i][j] + " ");
            }
            System.out.println();
        }
    }
}
